package com.foreknow.controller;

import com.foreknow.bean.Admin;
import com.foreknow.service.AdminService;
import com.foreknow.service.impl.AdminServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class LoginServlet  extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        resp.setContentType("text/html;charset=utf-8");
        PrintWriter writer = resp.getWriter();
        //获取请求参数
        String username = req.getParameter("email");    //输入的email 必须和输入框 input 的name 属性一样  即 name = "email"
        String password = req.getParameter("password");

        writer.println("用户名"+username);
        writer.println("密码"+password);

//        调用Model servers 和dao   连接数据库
        AdminService service = new AdminServiceImpl();

        Admin admin = service.isValidate(username, password);
        if(admin != null){
//            跳转资源，转发   ?后面为传参  ？key = value

            req.getRequestDispatcher("/manage?q=list").forward(req,resp);



        }else {
            writer.println("失败");
        }

    }
}
